define(['jquery', 'bootstrap', 'backend', 'table', 'form','vue'], function ($, undefined, Backend, Table, Form,Vue) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'log/withdrawlog/index',
                    add_url: 'log/withdrawlog/add'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                search:false,
                columns: [
                    [
                        {field: 'state', checkbox: true },
                        {field: 'id', title: 'ID',sortable:true},
                        {field: 'money', title: __('Money'),searchable:false},
                        {field: 'user_nickname', title: __('User nickname'),searchable:false},
                        {field: 'property_name', title: __('Property name'),searchable:false},
                        {field: 'status', title: __('Status'),formatter:function(value,row,index){
                            value = '' + value;
                            switch (value){
                                case '0':
                                    return __('Wait');
                                case '1':
                                    return __('Verify passed');
                                case '2':
                                    return __('Verify fail');
                                default:
                                    return __('Wait');
                            }
                        },searchList: {'0': __('Wait'), '1': __('Verify passed'),'2':__('Verify fail')}, style: 'min-width:100px;'
                        },
                        {field: 'remark', title: __('Verify desc'),searchable:false},
                        {field: 'create_time', title: __('Create time'),
                            formatter: Table.api.formatter.datetime, operate: 'BETWEEN',
                            type: 'datetime', addclass: 'datetimepicker',
                            data: 'data-date-format="YYYY-MM-DD"'
                        },
                        {field: 'operate', title: __('Verify'), table: table, events: Table.api.events.operate,
                            buttons: [{
                                name: 'verify',
                                text: __('Verify'),
                                icon: 'fa fa-check',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                url: 'log/withdrawlog/verify'
                            }],
                            formatter: function (value, row, index) {
                                if(Config.user_type == 0 || Config.user_type == 1) {
                                    if (row.status == '1') {
                                        return '<a href="#" class="btn btn-info btn-xs btn-success" title="审核通过"><i class="fa fa-check"></i>通过</a>';
                                    } else if (row.status == '2') {
                                        return '<a href="#" class="btn btn-info btn-xs btn-warning" title="审核不通过"><i class="fa fa fa-close"></i>不通过</a>';
                                    }
                                    return Table.api.formatter.operate.call(this, value, row, index);
                                }
                                else{
                                    if (row.status == '1') {
                                        return '<a href="#" class="btn btn-info btn-xs btn-success" title="审核通过"><i class="fa fa-check"></i>通过</a>';
                                    } else if (row.status == '2') {
                                        return '<a href="#" class="btn btn-info btn-xs btn-warning" title="审核不通过"><i class="fa fa fa-close"></i>不通过</a>';
                                    }
                                    else{
                                        return '<a href="#" class="btn btn-xs " title="审核中"><i class=""></i>审核中</a>';
                                    }
                                    // return Table.api.formatter.operate.call(this, value, row, index);
                                }
                            }
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add:function () {
            Form.api.bindevent($("form[role=form]"));
            $('#money_over').html("可提金额:"+Config.money);
            var wv = new Vue({
                el:'#money_input',
                data:{
                    money:0
                    ,poundage:Config.poundage
                    ,money_over: Config.money
                }
                ,watch:{
                    money:function (val) {
                        var that = this;
                        if(val < 0 || val==''){
                            that.money = 0;
                        }
                        if(val > parseFloat(that.money_over)){
                            that.money = that.money_over;
                        }
                        //计算实际到账和手续费
                        var poundage = (parseFloat(that.money) * parseFloat(that.poundage)).toFixed(2);
                        // console.info(parseFloat(poundage));
                        $('#money_true').html('实际到账:'+(parseFloat(that.money).toFixed(2)-poundage));
                        // console.info(parseFloat(that.money).toFixed(2));
                        $('#pounage').html('手续费:'+parseFloat(poundage));
                    },
                }
            });
            wv.money = Config.money;
        },
        verify: function () {
            Form.api.bindevent($("form[role=form]"));
        }
    };
    return Controller;
});